package com.example.recycler_view;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private RecyclerView list_view;
    private List<mode> list=new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        content();  //初始化数据
        initView(); //设置布局功能
    }

    public void initView() {
        list_view=findViewById(R.id.ReyclerView);   //寻找视图
        //设置reCyclerView的布局方式
        LinearLayoutManager layout=new LinearLayoutManager(this);
        layout.setOrientation(LinearLayoutManager.VERTICAL);
        list_view.setLayoutManager(layout);
        //创建适配器
        Recycler_Adapter adapter=new Recycler_Adapter(list);
        //设置适配器
        list_view.setAdapter(adapter);
    }
    //设置数据
    public void content()
    {
        for (int i=0;i<5;i++)
        {
            list.add(new mode("标题1","最时尚，最好玩，最好看的app",R.mipmap.t1));
            list.add(new mode("标题2","最时尚，最好玩，最好看的app",R.mipmap.t2));
            list.add(new mode("标题3","最时尚，最好玩，最好看的app",R.mipmap.t3));
        }
    }
}
